package offer

import (
	// "bp/cache"
	sqlc "bp/db/sqlc"
)

type CouponPtrToOfferPtrFunc func(*sqlc.Coupon) *Offer
type PromotionPtrToOfferPtrFunc func(*sqlc.Promotion) *Offer
type MemberCouponPtrToOfferPtrFunc func(*sqlc.MemberCoupon) *Offer

// ConvCouponPtrToOfferPtr get func of *sqlc.Coupon => *Offer
func (s *OfferComServiceImp) ConvCouponPtrToOfferPtr() CouponPtrToOfferPtrFunc {
	return func(ptr *sqlc.Coupon) *Offer {
		if ptr == nil {
			return nil
		}
		return &Offer{
			ID:                      ptr.ID,
			Nature:                  ptr.Nature,
			Name:                    ptr.Name,
			Desc:                    ptr.Desc.String,
			Tags:                    ptr.Tags,
			OfferCategory:           ptr.OfferCategory,
			OfferType:               ptr.OfferType,
			NeedVerifyQualification: ptr.NeedVerifyQualification,
			QualifyTypes:            ptr.QualifyTypes,
			Price:                   ptr.Price,
			Quota:                   ptr.Quota,
			OffMaximum:              ptr.OffMaximum,
			UsePeriodType:           ptr.UsePeriodType,
			Days:                    ptr.Days.Int32,
			AvailableAfterGotDays:   ptr.AvailableAfterGotDays.Int32,
			Begined:                 ptr.UseBegined.Time,
			Ended:                   ptr.UseEnded.Time,
		}
	}
}

func (s *OfferComServiceImp) MapCouponPtrsToOfferPtrs(list []*sqlc.Coupon, conv CouponPtrToOfferPtrFunc) []*Offer {
	ptrs := make([]*Offer, len(list))
	for i, entity := range list {
		ptrs[i] = conv(entity)
	}
	return ptrs
}

// ConvCouponPtrToOfferPtr get func of *sqlc.Promotion => *Offer
func (s *OfferComServiceImp) ConvPromotionPtrToOfferPtr() PromotionPtrToOfferPtrFunc {
	return func(ptr *sqlc.Promotion) *Offer {
		if ptr == nil {
			return nil
		}
		return &Offer{
			ID:                      ptr.ID,
			Nature:                  ptr.Nature,
			Name:                    ptr.Name,
			Desc:                    ptr.Desc.String,
			Tags:                    ptr.Tags,
			OfferCategory:           ptr.OfferCategory,
			OfferType:               ptr.OfferType,
			NeedVerifyQualification: ptr.NeedVerifyQualification,
			QualifyTypes:            ptr.QualifyTypes,
			Price:                   ptr.Price,
			Quota:                   ptr.Quota,
			OffMaximum:              ptr.OffMaximum,
			Begined:                 ptr.Begined,
			Ended:                   ptr.Ended,
		}
	}
}

func (s *OfferComServiceImp) MapPromotionPtrsToOfferPtrs(list []*sqlc.Promotion, conv PromotionPtrToOfferPtrFunc) []*Offer {
	ptrs := make([]*Offer, len(list))
	for i, entity := range list {
		ptrs[i] = conv(entity)
	}
	return ptrs
}

// ConvMemberCouponPtrToOfferPtr get func of *sqlc.MemberCoupon => *Offer
func (s *OfferComServiceImp) ConvMemberCouponPtrToOfferPtr() MemberCouponPtrToOfferPtrFunc {
	return func(ptr *sqlc.MemberCoupon) *Offer {
		if ptr == nil {
			return nil
		}
		return &Offer{
			ID:            ptr.ID,
			Nature:        ptr.Nature,
			Name:          ptr.Name,
			Desc:          ptr.Desc.String,
			Tags:          ptr.Tags,
			OfferCategory: ptr.OfferCategory,
			OfferType:     ptr.OfferType,
			Price:         ptr.Price,
			Quota:         ptr.Quota,
			OffMaximum:    ptr.OffMaximum,
			Begined:       ptr.Begined,
			Ended:         ptr.Ended,
		}
	}
}

func (s *OfferComServiceImp) MapMemberCouponPtrsToOfferPtrs(list []*sqlc.MemberCoupon, conv MemberCouponPtrToOfferPtrFunc) []*Offer {
	ptrs := make([]*Offer, len(list))
	for i, entity := range list {
		ptrs[i] = conv(entity)
	}
	return ptrs
}
